home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 20 / Cream of the Crop 20 (Terry Blount) (1996).iso / os2 / eaclib.zip / EA.HPP < prev    next >
C/C++ Source or Header  |  1996-05-22  |  5KB  |  159 lines

  1. /* --------------------------------------------------------------------------
  2.  * $RCSfile: EA.hpp,v $
  3.  * $Revision: 1.1 $
  4.  * $Date: 1996/05/22 20:59:55 $
  5.  * $Author: Bablok $
  6.  * --------------------------------------------------------------------------
  7.  * Synopsis:
  8.  *
  9.  * Interface for class EA. This class wraps the extended attributes API of
  10.  * OS/2.
  11.  *
  12.  * This file is part of the EA classlib package.
  13.  * Copyright Bernhard Bablok, 1996
  14.  *
  15.  * The EA classlib package is distributed in the hope that it will be
  16.  * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
  17.  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  18.  *
  19.  * You may use the classes in the package to any extend you wish. You are
  20.  * allowed to change and copy the source of the classes, as long as you keep
  21.  * the copyright notice intact and as long as you document the changes you made.
  22.  *
  23.  * You are not allowed to sell the EA classlib package or a modified version
  24.  * thereof, but you may charge for costs of distribution media.
  25.  *
  26.  * --------------------------------------------------------------------------
  27.  * Change-Log:
  28.  *
  29.  * $Log: EA.hpp,v $
  30.  * Revision 1.1  1996/05/22 20:59:55  Bablok
  31.  * Initial revision
  32.  *
  33.  * -------------------------------------------------------------------------- */
  34.  
  35. #ifndef EA_H
  36.   #define EA_H
  37.  
  38.   #ifndef INCL_BASE
  39.      #define INCL_BASE
  40.      #include <os2.h>
  41.   #endif
  42.   #ifndef _ISTRING_
  43.      #include <istring.hpp>
  44.   #endif
  45.  
  46.   #define MSG_FILE               "EALerr.msg"
  47.   #define ERR_MEM_ALLOC_FAILED   1
  48.   #define ERR_NO_EA_NAME         2
  49.   #define ERR_EALIST_EMPTY       3
  50.   #define ERR_NOT_MULTI_VALUED   4
  51.   #define ERR_INVALID_TYPE       5
  52.   #define ERR_ELEMENT_COUNT      6
  53.  
  54.   class EAList;
  55.  
  56.   class EA {
  57.  
  58.      friend class EAList;
  59.      friend const IString& key(const EA& ea) {return ea.mName;}
  60.  
  61.      public:
  62.  
  63.         // constructors, destructor   ------------------------------------------
  64.  
  65.         EA(const IString& name, const void* buffer, unsigned long length,
  66.                                           USHORT type=EAT_BINARY, BYTE flag=0) :
  67.                                 mName(name), mValue(buffer,length), mType(type),
  68.                                                                    mFlag(flag) {
  69.            mName.upperCase();
  70.         }
  71.         EA(const IString& name="", const IString& value="", BYTE flag=0) :
  72.                      mName(name), mValue(value), mType(EAT_ASCII), mFlag(flag) {
  73.            mName.upperCase();
  74.         }
  75.         EA(const IString& name, const EAList& EAList, BYTE flag=0);
  76.         ~EA() {}
  77.  
  78.         // get/set functions   -------------------------------------------------
  79.  
  80.         const IString& value() const {return mValue;}
  81.         EA& setValue(const IString& value) {
  82.            mValue = value;
  83.            return *this;
  84.         }
  85.         const IString& name() const {return mName;}
  86.         EA& setName(const IString& name) {
  87.            mName = name;
  88.            return *this;
  89.         }
  90.         USHORT  type() const {return mType;}
  91.         static IString typeAsString(USHORT type);
  92.         IString typeAsString() const {
  93.            return typeAsString(mType);
  94.         }
  95.         EA& setType(USHORT type) {
  96.            mType = type;
  97.            return *this;
  98.         }
  99.         BYTE   flag() const {return mFlag;}
  100.         EA& setFlag(BYTE flag) {
  101.            mFlag = flag;
  102.            return *this;
  103.         }
  104.  
  105.         USHORT numValues() const;
  106.         USHORT codePage() const;
  107.  
  108.         // interaction with physical files   -----------------------------------
  109.  
  110.         EA& read(const char* pathName) {           // read EA from file
  111.            return read((PVOID) pathName,true);
  112.         }
  113.         EA& read(HFILE fileHandle) {
  114.            return read((PVOID) &fileHandle,false);
  115.         }
  116.  
  117.         EA& write(const char* pathName) {          // write EA to file
  118.            return write((PVOID) pathName,true);
  119.         }
  120.         EA& write(HFILE fileHandle) {
  121.            return write((PVOID) &fileHandle,false);
  122.         }
  123.  
  124.         EA& remove(const char* pathName) {         // delete EA from file
  125.            return remove((PVOID) pathName,true);
  126.         }
  127.         EA& remove(HFILE fileHandle) {
  128.            return remove((PVOID) &fileHandle,false);
  129.         }
  130.  
  131.      private:
  132.  
  133.         // data members   ------------------------------------------------------
  134.  
  135.         IString mName, mValue;
  136.         USHORT  mType;
  137.         BYTE    mFlag;
  138.  
  139.         // auxiliary functions   -----------------------------------------------
  140.  
  141.         EA(FEA2* fea2);
  142.  
  143.         EA& read(PVOID fileRef, Boolean isPathName);
  144.         EA& write(PVOID fileRef, Boolean isPathName);
  145.         EA& remove(PVOID fileRef, Boolean isPathName);
  146.  
  147.         static Boolean isLengthPreceded(USHORT type);
  148.         Boolean EA::isLengthPreceded() const {
  149.            return isLengthPreceded(mType);
  150.         }
  151.  
  152.         ULONG createFEA2(char *buffer) const;
  153.         GEA2LIST* createGEA2LIST() const;
  154.         FEA2LIST* createFEA2LIST() const;
  155.         FEA2LIST* createFEA2LISTBuffer() const;
  156.         FEA2LIST* createFEA2LISTBuffer(PVOID fileRef, Boolean isPathName) const;
  157.      };
  158. #endif
  159.